var express = require('express')
var router = express.Router()
const { getAll, getOne, exec } = require('../db/index')

router.get('/checkName', async (req, res) => {
  let sql = `select username from blog_user where username = ${req.query.username}`
  const data = await getAll(sql)
  console.log(data)
  res.send({
    code: 0,
    message: '查询成功',
    result: data,
  })
})

router.post('/', async (req, res) => {
  const { username, email, password } = req.body
  let sql = `insert into blog_user (username,email,password) values('${username}','${email}','${password}')`
  await exec(sql)
  res.send({
    code: 0,
    message: '注册成功',
  })
  return
})

module.exports = router
